using Unity.VisualScripting;
using UnityEngine;
using static WaterCylinder.Input;

public class Player : Entity
{   
    public Weapon playerWeapon;
    [Tooltip("Disable")]
    public HandWeapon weapon;
    Bag _bag;
    Bag bag{
        get{
            if(_bag != null){
                _bag = GetComponent<Bag>();
            }
            return _bag;
        }
    }
    
    PlayerController controller;

    //玩家初始化
    protected override void OnStart(){
        GameManager.instance.player = this;
        controller = new PlayerController{ player = this };//绑定控制器 

        Debug.Log(GameManager.instance.playerConfig.model);//输出玩家配置中的操作模式

        weapon = HandWeapon.CreatHandWeapon(this, playerWeapon);
        //根据射速设置武器射速
        weapon.weapon.pickEvent.AddListener(i=>{
            Weapon w = (Weapon)i;
            w.shotTime = 1 / baseAttribute.attackspeed.value;
        });
        //weapon.weapon.useEvent.AddListener((i)=>Debug.Log("呃呃呃"));
    }

    protected override void OnUpdate(){
        //玩家移动
        SmoothMove(controller.GetMoveToward(), speed, 2);
        //玩家输入检测
        if(InputOperaUp){
            weapon.UseWeapon(set:b=>{
                b.toward = ToMouse();
                b.speed = 10;
            });
        }
    }
}
